package com.jilian.mydemo.modul.order.adapter;

import android.app.Activity;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.jilian.mydemo.R;
import com.jilian.mydemo.common.dto.ProductDetailDto;
import com.jilian.mydemo.common.vo.ProductVO;
import com.jilian.mydemo.listener.CustomItemClickListener;
import com.jilian.mydemo.utils.EmptyUtils;

import java.util.List;

/**
 * 服务产品
 */
public class ProductAdapter extends RecyclerView.Adapter<ProductAdapter.ViewHolder> {
    private Activity mContext;
    private List<ProductVO> datas;
    private CustomItemClickListener listener;


    public ProductAdapter(Activity context, List<ProductVO> datas, CustomItemClickListener listener) {
        mContext = context;
        this.datas = datas;
        this.listener = listener;

    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_order_detail, parent, false);
        ViewHolder viewHolder = new ViewHolder(view, listener);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {

        holder.tvName.setText("服务产品信息" + (position+1));
        //产品编号
        holder.tvProductNo.setText(datas.get(position).getProductCode());
        //机身号
        holder.tvFuselageNo.setText(datas.get(position).getSerialNum());
        //滤芯号
        holder.tvElementNo.setText(datas.get(position).getLvXinCode());
        if (position == datas.size() - 1) {
            holder.vLine.setVisibility(View.GONE);
        } else {
            holder.vLine.setVisibility(View.VISIBLE);
        }

    }

    @Override
    public int getItemCount() {
        return datas == null ? 0 : datas.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {


        private TextView tvProductNo;
        private TextView tvFuselageNo;
        private TextView tvElementNo;
        private TextView tvName;
        private View vLine;


        public ViewHolder(final View itemView, final CustomItemClickListener listener) {
            super(itemView);
            tvName = (TextView) itemView.findViewById(R.id.tv_name);
            tvProductNo = (TextView) itemView.findViewById(R.id.tv_product_no);
            tvFuselageNo = (TextView) itemView.findViewById(R.id.tv_fuselage_no);
            tvElementNo = (TextView) itemView.findViewById(R.id.tv_element_no);
            vLine = (View) itemView.findViewById(R.id.v_line);
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    listener.onItemClick(itemView, getAdapterPosition());
                }
            });


        }

    }
}
